
package com.eyedog.video.db2.tables;

import android.content.ContentValues;
import android.database.Cursor;

import com.eyedog.video.entity.VideoEntity;

public class VideoTable extends BaseTable<VideoEntity> {

    public static final String TABLE_NAME = "t_video";

    public static final String ID = "id";

    public static final String DESC = "desc";

    public static final String AUTHOR = "author";

    public static final String VOD_NAME = "vod_name";

    public static final String VOD_PIC = "vod_pic";

    public static final String VOD_URL = "vod_url";

    private static VideoTable instance;

    public static VideoTable getInstance() {
        if (instance == null) {
            instance = new VideoTable();
        }
        return instance;
    }

    @Override
    void addColumns() {
        addColumnInteger(ID);
        addColumnText(DESC);
        addColumnText(AUTHOR);
        addColumnText(VOD_NAME);
        addColumnText(VOD_PIC);
        addColumnText(VOD_URL);
    }

    @Override
    String getTableName() {
        return TABLE_NAME;
    }

    @Override
    ContentValues getCVFromEntity(VideoEntity videoEntity) {
        if (videoEntity != null) {
            ContentValues contentValues = new ContentValues();
            contentValues.put(ID, videoEntity.getId());
            contentValues.put(DESC, videoEntity.getDesc());
            contentValues.put(AUTHOR, videoEntity.getAuthor());
            contentValues.put(VOD_NAME, videoEntity.getVod_name());
            contentValues.put(VOD_PIC, videoEntity.getVod_pic());
            contentValues.put(VOD_URL, videoEntity.getVod_url());
            return contentValues;
        }
        return null;
    }

    @Override
    VideoEntity getEntityFromCursor(Cursor cursor) {
        VideoEntity entity = null;
        if (cursor != null && !cursor.isClosed()) {
            entity = new VideoEntity();
            entity.setId(cursor.getInt(cursor.getColumnIndex(ID)));
            entity.setDesc(cursor.getString(cursor.getColumnIndex(DESC)));
            entity.setAuthor(cursor.getString(cursor.getColumnIndex(AUTHOR)));
            entity.setVod_name(cursor.getString(cursor.getColumnIndex(VOD_NAME)));
            entity.setVod_pic(cursor.getString(cursor.getColumnIndex(VOD_PIC)));
            entity.setVod_url(cursor.getString(cursor.getColumnIndex(VOD_URL)));
        }
        return entity;
    }
}
